import requests
from lxml import etree

# NBA 数据
url = 'https://nba.hupu.com/stats/players'
headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Accept-Encoding': 'gzip, deflate, br, zstd',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    'Cookie': 'Hm_lvt_4fac77ceccb0cd4ad5ef1be46d740615=1744857305; Hm_lpvt_4fac77ceccb0cd4ad5ef1be46d740615=1744857305; HMACCOUNT=80BCC7E24F98D420; Hm_lvt_b241fb65ecc2ccf4e7e3b9601c7a50de=1744857305; Hm_lpvt_b241fb65ecc2ccf4e7e3b9601c7a50de=1744857305; Hm_lvt_a3d34dd67fa1fb34b2b430bbaaa2a5bf=1744857305; Hm_lpvt_a3d34dd67fa1fb34b2b430bbaaa2a5bf=1744857305',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
}
resp = requests.get(url, headers=headers)
e = etree.HTML(resp.text)
# print(resp.text)
# 球员名字
names = e.xpath('//tbody/tr/td[2]/a/text()')
# 所在球队
teams = e.xpath('//tbody/tr/td[3]/a/text()')
# 得分
scores = e.xpath('//tbody/tr[not(@class="color_font1 bg_a")]/td[4]/text()')
# print(len(names))
# print(names)
# print(len(teams))
# print(teams)
# print(len(scores))
# print(scores)
list_data = []
for name, team, score in zip(names, teams, scores):
    list_data.append({
        'name': name,
        'team': team,
        'score': score,
    })

print(list_data)
